#include "ban.h"
#include <stdlib.h>
#include <stdio.h>
#include <string.h>

list *
add_kb (list * tete, char *chan, char *nick, char *raison)
{
  list *t = (list *) malloc (sizeof (list));
  t->chan = (char *) malloc (strlen (chan) + 1);
  t->nick = (char *) malloc (strlen (nick) + 1);
  t->raison = (char *) malloc (strlen (raison) + 1);
  strcpy (t->raison, raison);
  strcpy (t->chan, chan);
  strcpy (t->nick, nick);
  t->next = tete;
  return t;
}

list *
rm_kb (list * tete, list * k)
{
  list *tmp = NULL, *prev = NULL, *move = NULL;
  for (tmp = tete; tmp != NULL; prev = tmp, tmp = tmp->next)
    if (tmp == k)
      {
	move = tmp->next;
	free (tmp->chan);
	free (tmp->nick);
	free (tmp->raison);
	free (tmp);
	if (prev == NULL)
	  return move;

	prev->next = move;
	return tete;
      }
  return tete;
}

list *
get_element (list * tete, char *nick)
{
  list *p;
  for (p = tete; p != NULL; p = p->next)
    if (!strcasecmp (nick, p->nick))
      return p;

  return NULL;
}
